﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ECommerce.DAO.SQL.Controles
{
    public static class WebControl
    {
        internal static System.Web.UI.Control[] GetControlesFromCompositeControl(System.Web.UI.Control result)
        {
            throw new NotImplementedException();
        }

        internal static System.Web.UI.WebControls.ListItem[] GetAttributesFromControl(System.Web.UI.Control result)
        {
            throw new NotImplementedException();
        }

        internal static System.Web.UI.WebControls.CommandEventHandler[] GetEventsByControl(System.Web.UI.WebControls.Button Button)
        {
            throw new NotImplementedException();
        }

        internal static System.Web.UI.ControlCollection GetControlesMarcoByPerfil(ECommerce.Model.Seguridad.Perfil Perfil)
        {
            throw new NotImplementedException();
        }

        //Select Methods Helpers
        public static ECommerce.Model.Controles.WebControl[] GetWebControls(string StoreProcedure, ECommerce.DAO.SQL.Parámetro[] Parámetros)
        {
            ECommerce.Model.Controles.WebControl WebControl = new ECommerce.Model.Controles.WebControl();
            Type DynamicType = WebControl.GetType();
            return ECommerce.DAO.SQL.Controles.WebControl.GetWebControlsFromObjects(ECommerce.DAO.SQL.SqlHelper.Get(StoreProcedure, Parámetros, DynamicType));
        }
        public static ECommerce.Model.Controles.WebControl[] GetWebControlsFromObjects(ECommerce.Model.Objeto[] Objetos)
        {
            List<ECommerce.Model.Controles.WebControl> result = new List<ECommerce.Model.Controles.WebControl>();
            ECommerce.Model.Controles.WebControl WebControl;
            foreach (ECommerce.Model.Objeto Objeto in Objetos)
            {
                WebControl = new ECommerce.Model.Controles.WebControl();
                WebControl = (ECommerce.Model.Controles.WebControl)Objeto;
                if (WebControl != null)
                    if (WebControl.Id != 0)
                        result.Add(WebControl);
            }
            return result.ToArray();
        }

        //Select Methods
        public static ECommerce.Model.Controles.WebControl GetWebControlById(int Id)
        {
            List<ECommerce.DAO.SQL.Parámetro> Parámetros = new List<ECommerce.DAO.SQL.Parámetro>();
            ECommerce.DAO.SQL.Parámetro Parámetro = new ECommerce.DAO.SQL.Parámetro("@Id", System.Data.SqlDbType.BigInt, Id);
            Parámetros.Add(Parámetro);
            ECommerce.Model.Controles.WebControl[] Controles = ECommerce.DAO.SQL.Controles.WebControl.GetWebControls("GetWebControlById", Parámetros.ToArray());
            if (Controles != null)
                if (Controles.Length > 0)
                    return Controles[0];
            return null;
        }
        public static ECommerce.Model.Controles.WebControl[] GetWebControlsDelSistema()
        {
            List<ECommerce.DAO.SQL.Parámetro> Parámetros = new List<ECommerce.DAO.SQL.Parámetro>();
            return ECommerce.DAO.SQL.Controles.WebControl.GetWebControls("GetWebControlesDelSistema", Parámetros.ToArray());
        }
        public static ECommerce.Model.Controles.WebControl[] GetWebControlsByWebControlId(int WebControlId)
        {
            List<ECommerce.DAO.SQL.Parámetro> Parámetros = new List<ECommerce.DAO.SQL.Parámetro>();
            ECommerce.DAO.SQL.Parámetro Parámetro = new Parámetro("@Id", System.Data.SqlDbType.BigInt, WebControlId);
            Parámetros.Add(Parámetro);
            return ECommerce.DAO.SQL.Controles.WebControl.GetWebControls("GetWebControlsByWebControlId", Parámetros.ToArray());
        }

        //Insert Methods
        public static int SetWebControl(ECommerce.Model.Controles.WebControl WebControl)
        {
            List<ECommerce.DAO.SQL.Parámetro> Parámetros = new List<ECommerce.DAO.SQL.Parámetro>();
            ECommerce.DAO.SQL.Parámetro Parámetro = new ECommerce.DAO.SQL.Parámetro("@Id", System.Data.SqlDbType.BigInt, WebControl.Id);
            Parámetros.Add(Parámetro);
            Parámetro = new ECommerce.DAO.SQL.Parámetro("@Tipo", System.Data.SqlDbType.NVarChar, WebControl.Tipo.ToString());
            Parámetros.Add(Parámetro);
            return ECommerce.DAO.SQL.SqlHelper.Insert("SetWebControl", Parámetros.ToArray());
        }
        public static void AddWebControlToWebControl(ECommerce.Model.Controles.WebControl WebControlHijo, ECommerce.Model.Controles.WebControl WebControlPadre)
        {
            List<ECommerce.DAO.SQL.Parámetro> Parámetros = new List<ECommerce.DAO.SQL.Parámetro>();
            ECommerce.DAO.SQL.Parámetro Parámetro = new ECommerce.DAO.SQL.Parámetro("@IdWebControlPadre", System.Data.SqlDbType.BigInt, WebControlPadre.Id);
            Parámetros.Add(Parámetro);
            Parámetro = new ECommerce.DAO.SQL.Parámetro("@IdWebControlHijo", System.Data.SqlDbType.BigInt, WebControlHijo.Id);
            Parámetros.Add(Parámetro);
            ECommerce.DAO.SQL.SqlHelper.Insert("AddWebControlToWebControl", Parámetros.ToArray());
        }

    }
}
